import Fingerprint from 'fingerprintjs';
import Fingerprint2 from 'fingerprintjs2';
const KEY = 'ballbet-uuid';

export const generateUUID = () => {
  return new Promise(resolve => {
    Fingerprint2.get(components=>{
      let values = components.map(item => item.value);
      const uuid = Fingerprint2.x64hash128(values.join(""), 31); //生成指纹信息
      localStorage.setItem(KEY, uuid);
      resolve(uuid);
    });
  });
};

export const getUUID = () => {
  let uuid = localStorage.getItem(KEY);
  // console.log(`🍺🍺🍺🍺🍺🍺🍺🍺🍺 uuid => ${uuid} 🍺🍺🍺🍺🍺🍺🍺🍺🍺`);
  if (!uuid) {
    uuid = new Fingerprint({ canvas: true }).get();
    generateUUID();
  }
  return uuid;
};
